package com.tunan.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.tunan.system.service.TokenService;
import com.tunan.utils.RedisUtils;

import redis.clients.jedis.exceptions.JedisException;

/**
 * 
 * @ClassName: StartupRunner
 * @Description: 应用启动时用运行
 * @author: kinda
 * @date: 2016年4月1日 上午10:00:10
 */
@Component
@Order(value = 1)
public class StartupRunner implements CommandLineRunner {

	@Autowired
	private RedisUtils redisUtils;

	@Autowired
	private TokenService tokenService;

	@Override
	public void run(String... arg0) throws Exception {
		try {
			if ("PONG".equalsIgnoreCase(tokenService.redisLive())) {
				redisUtils.setRedisLived(true);
			} else {
				redisUtils.setRedisLived(false);
			}
		} catch (JedisException e) {
			redisUtils.setRedisLived(false);
		}
	}

}
